package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.vo.CheckGroupVO;
import com.itheima.health.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SetmealMapper extends BaseMapper<Setmeal> {

    @Insert("insert into t_setmeal_checkgroup values(#{sid},#{checkgroupId})")
    void addCheckgroupIdBySetmealId(@Param("sid") Integer sid, @Param("checkgroupId")Integer checkgroupId);

    @Delete("delete from t_setmeal_checkgroup where SETMEAL_ID=#{id}")
//    @Delete("delete from t_checkgroup_checkitem where checkgroup_id=#{id}")
    void deleteBySetmealId(Integer id);

    @Select("select * from t_setmeal where id =#{id}")
    SetmealVO findSetMealDetail(Integer id);


    @Select("select * " +
            "from t_setmeal_checkgroup tsc,t_checkgroup tcg " +
            "where tcg.ID = tsc.CHECKGROUP_ID and tsc.SETMEAL_ID = #{id}")
    List<CheckGroupVO> findCheckGroup(Integer id);

    @Select("select tc.name from t_checkgroup_checkitem tcc,t_checkitem tc where CHECKGROUP_ID = #{checkGroupVOId} and tcc.CHECKITEM_ID = tc.id")
    List<CheckItem> findCheckItemByCheckGroupVOId(Integer id);

    @Select("select * from t_setmeal where id =#{id}")
    SetmealVO findById(Integer id);
}
